package ca

import (
	"testing"
)

//func TestEnrollAdmin(t *testing.T) {
//	fcc := NewCooridnator("")
//
//	/*
//		fabric-ca-client enroll -d -u https://admin:adminpw@localhost:7054 --home /home/francis/fabric-ca/client-config --tls.certfiles /home/francis/fabric-ca/server-config/ca-cert.pem
//	*/
//	if err := fcc.enrollAdmin("/home/francis/fabric-ca/server-config/ca-cert.pem",
//		"/home/francis/fabric-ca/client-config",
//		"https://admin:adminpw@localhost:7054"); err != nil {
//		t.Fatalf("enrollAdmin error:%+v", err)
//	}
//}

//func TestResgister(t *testing.T) {
//	fcc := NewCooridnator("")
//
//	/*
//		fabric-ca-client register -d --id.name orderer1-org1 --id.secret ordererpw --id.type orderer -u https://localhost:7054
//		fabric-ca-client register -d --id.name admin-org1 --id.secret org1adminpw --id.type admin --id.attrs "hf.Registrar.Roles=client,hf.Registrar.Attributes=*,hf.Revoker=true,hf.GenCRL=true,admin=true:ecert,abac.init=true:ecert" -u https://localhost:7054
//	*/
//	flags := NewFlags()
//	flags.With("--id.name", "orderer1-org1")
//	flags.With("--id.secret", "ordererpw")
//	flags.With("--id.type", "orderer")
//	flags.With("-u", "https://localhost:7054")
//	flags.With("--home", "/home/francis/fabric-ca/client-config")
//	flags.With("--tls.certfiles", "/home/francis/fabric-ca/server-config/ca-cert.pem")
//
//	if err := fcc.register(flags); err != nil {
//		t.Fatalf("register error:%+v", err)
//	}
//}

func TestEnroll(t *testing.T) {
	fcc := NewCooridnator("/home/francis/fabric-ca/client-config", "orggo.zhaowu.com")

	/*
		export FABRIC_CA_CLIENT_HOME=/tmp/hyperledger/org0/admin
		export FABRIC_CA_CLIENT_TLS_CERTFILES=/tmp/hyperledger/org0/orderer/assets/ca/org0-ca-cert.pem
		export FABRIC_CA_CLIENT_MSPDIR=msp
		fabric-ca-client enroll -d -u https://orderer1-org1:ordererpw@localhost:7054
	*/
	flags := NewFlags()
	flags.With("-u", "https://orderer1-org1:ordererpw@localhost:7054")
	flags.With("--home", "/home/francis/fabric-ca/client-config/orderer1-org1")
	//flags.With("--tls.certfiles", "/workspace/gopath/src/gitee.com/blockchainsAio/data/stack/tmpl/res/bft3/crypto-config/ordererOrganizations/zhaowu.com/ca/ca.zhaowu.com-cert.pem")
	flags.With("--tls.certfiles", "/home/francis/fabric-ca/server-config/ca-cert.pem")

	if err := fcc.enroll(flags); err != nil {
		t.Fatalf("enroll error:%+v", err)
	}
}
